﻿namespace WpfDevelopment.MVVM.Tests
{
    using System;
    using System.Windows.Input;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System.Threading;

    public class RelayCommandTest
    {
        [TestClass]
        public class CanExecute
        {
            [TestMethod]
            public void Must_return_true_if_it_can_execute()
            {
                // Arrange
                var sut = new RelayCommand();
                sut.CanExecuteCommand = f => true;
                bool returnValue = false;

                // Act
                returnValue = sut.CanExecute(string.Empty);

                // Assert
                Assert.IsTrue(returnValue);
            }

            [TestMethod]
            public void Must_return_false_if_it_cannot_execute()
            {
                // Arrange
                var sut = new RelayCommand();
                sut.CanExecuteCommand = f => false;
                bool returnValue = true;

                // Act
                returnValue = sut.CanExecute(string.Empty);

                // Assert
                Assert.IsFalse(returnValue);
            }

            [TestMethod]
            public void Must_use_the_CanExecute_action_to_check_if_action_can_execute()
            {
                // Arrange
                var sut = new RelayCommand();
                sut.CanExecuteCommand = f => (bool)f;

                // Act
                var resultTrue = sut.CanExecute(true);
                var resultFalse = sut.CanExecute(false);

                // Assert
                Assert.IsTrue(resultTrue);
                Assert.IsFalse(resultFalse);
            }
        }
    }
}